﻿#pragma execution_character_set("utf-8")
#include "info_item.h"
#include "ui_info_item.h"

Info_item::Info_item(QString email,QString username,QString newInfo,QString newDate,int width,QWidget *parent) :
    QWidget(parent),
    email(email),
    username(username),
    ui(new Ui::Info_item)
{
    ui->setupUi(this);
    ui->name_LB->setText(username);
    ui->message_LB->setText(newInfo);
    ui->time_LB->setText(newDate);
    updateHeadImg();
    resizeWidth(width);
}

Info_item::~Info_item()
{
    delete ui;
}
void Info_item::updateHeadImg(){
    if(QFile::exists(QString("./accountData/Res/%1/headImg/head.png").arg(email)))
    {
        ui->img_LB->setStyleSheet(QString("\
            #img_LB{\
                border-radius:25px;\
                border-image:url('./accountData/Res/%1/headImg/head.png') 0 0 0 0 stretch stretch;\
            }\
        ").arg(email));
    }
}

void Info_item::setNormalStyle(){
    ui->Info_item_content->setStyleSheet(R"(
        #Info_item_content:hover{
            background-color:rgb(242, 242, 242);
        }
    )");
}
void Info_item::setClickStyle(){
    ui->Info_item_content->setStyleSheet(R"(
        #Info_item_content{
            background-color:rgb(235, 235, 235);
        }
    )");
}
QString Info_item::getEmail(){
    return this->email;
}
void Info_item::setNewInfo(QString newInfo,QString newDate){
    ui->message_LB->setText(newInfo);
    ui->time_LB->setText(newDate);
}
void Info_item::mousePressEvent(QMouseEvent* event){
    if(event->button()==Qt::LeftButton)
    {
        emit clicked(this);
    }
}
void Info_item::mouseDoubleClickEvent(QMouseEvent* event){
    if(event->button()==Qt::LeftButton){
        emit showComm(email,ui->name_LB->text(),ui->message_LB->text());
    }
}
void Info_item::resizeEvent(QResizeEvent *event){
    QSize newSize=event->size();
    QWidget* parent=this->parentWidget();
    ui->center_WT->setMaximumWidth(parent->width()-130);
    return QWidget::resizeEvent(event);
}
void Info_item::resizeWidth(int width){
    this->setMaximumWidth(width);
}
